package com.itgungnir.designpattern.observer.custom;

import java.util.ArrayList;
import java.util.List;

public class NewsOffice extends Subject {
	private List<Observer> observers;

	public NewsOffice() {
		super.name = "报社";
		this.observers = new ArrayList<Observer>();
	}

	@Override
	public void addObserver(Observer observer) {
		this.observers.add(observer);
	}

	@Override
	public void removeObserver(Observer observer) {
		int index = this.observers.indexOf(observer);
		if (index >= 0) {
			this.observers.remove(observer);
		}
	}

	@Override
	void notifyObservers() {
		if (this.observers.size() > 0) {
			for (Observer observer : this.observers) {
				observer.update(super.thing);
				observer.display();
			}
		}
	}
}